package p2pcdnsim.report;

import desmoj.core.report.HistogramReporter;


public class BandwidthReporter extends HistogramReporter {

	public BandwidthReporter(desmoj.core.simulator.Reportable informationSource) {
		super(informationSource);
		groupID = 1801; // see Reporter for more information about groupID
		numColumns = 3;
		columns = new String[numColumns];
		columns[0] = "Title";
		columns[1] = "(Re)set";
		columns[2] = "Total bytes";
		groupHeading = "Bandwidth";
	}

	@Override
	public String[] getEntries() {
		Bandwidth hist = (Bandwidth) source;
		return new String[] {hist.getName(),hist.resetAt().toString(),Long.toString(hist.getObservations())};
	}

	@Override
	public String[] getHistColumnTitles() {
		return new String[] {"","Component","bytes","%"};


	}

	@Override
	public String[][] getHistEntries() {
		Bandwidth band = (Bandwidth) source;
		band.sortItems();
		String histEntries[][] = new String[band.getNumberItems()+3][4];
		
		for (int j = 0; j < band.getNumberItems(); j++) {
			histEntries[j][0] = Integer.toString(j);
			histEntries[j][1] = band.getItem(j);
			histEntries[j][2] = Long.toString(band.getObservationsForItem(j));
			
			// % rounded percentage

			// calculate the percentage with 4 digits after the decimal
			// point
			double perc = java.lang.Math.rint(10000.0 * ((double) band
					.getObservationsForItem(j) * 100.0 / (double) band
					.getObservations())) / 10000.0;
			perc = java.lang.Math.rint(100.0 * perc) / 100.0;

			histEntries[j][3] = Double.toString(perc);
		}
		return histEntries;
	}

	@Override
	public int getHistNumColumns() {
		return 4;
	}

	@Override
	public int getNoOfCells() {
		return ((Bandwidth) source).getNumberItems();
	}
	 
    @Override
    public boolean isContinuingReporter() {
        return true;
    }

}
